
'use strict';
module.exports =  function (utc,f) {
        if (!+utc) {
            return "";
        }

        var cDate = new Date(utc),
            preZero = function (num) {
                return num < 10 ? "0" + num : num;
            };

        var fy =  cDate.getFullYear(),
            m = cDate.getMonth() + 1,
            d = cDate.getDate(),
            h = cDate.getHours(),
            minutes = cDate.getMinutes(),
            sec = cDate.getSeconds();


        return f.replace(/(yyyy|yy)|(mm)|(dd)|(hh)|(\:mm)|(ss)/ig,function (site) {

            switch (site.substr(0,1)) {
                case "y" :
                    return (fy + "").substr(-site.length);
                case "m" :
                    return site.length >= 2 ? preZero(m) : m;
                case "d" :
                    return site.length >= 2 ? preZero(d) : d;
                case "h" :
                    return site.length >= 2 ? preZero(h) : h;
                case ":" :
                    return ":" + (site.length >= 2 ? preZero(minutes) : minutes);
                case "s" :
                    return site.length >= 2 ? preZero(sec) : sec;

                // 无匹配制定格式，返回元字符串；
                default:
                    return site;
            }
        });
    };